package com.aso114.project.base;

import android.app.Application;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.StrictMode;
import android.support.multidex.MultiDex;

import com.umeng.analytics.AnalyticsConfig;
import com.umeng.commonsdk.UMConfigure;

/**
 * Created by Administrator on 2017/5/13.
 */

public class BaseApplication extends Application {

    public Context context;
    private static BaseApplication mInstance;


    public static BaseApplication getInstance() {
        return mInstance;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        context = getApplicationContext();
        mInstance = this;
        // 友盟统计 初始化
        UMConfigure.setEncryptEnabled (true);
        UMConfigure.init(this, getAppkey(), AnalyticsConfig.getChannel(this), UMConfigure.DEVICE_TYPE_PHONE, null);
        //7.0  file://格式的URI请求权限
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
            StrictMode.setVmPolicy(builder.build());
        }
    }

    private String getAppkey() {
        try {
            ApplicationInfo applicationInfo = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);
            String key = applicationInfo.metaData.getString("UMENG_APPKEY");
            return key;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return "";
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        // 多dex加载机制
        MultiDex.install(this);
    }
}
